package day20171003;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class TestJsoup1 {
    public static void main(String[] args) throws IOException {
        Document d= Jsoup.connect("https://www.tripadvisor.cn/Attraction_Review-g303770-d319081-Reviews-Jiuzhaigou_Natural_Reserve-Jiuzhaigou_County_Sichuan.html#REVIEWS").get();
        Elements e=d.select("div[class=detail_section address]");
        Elements e1=d.select("div[class=text]");
        Elements e2=d.select("div#REVIEWS").select("div[class=entry]");
        Elements e3=d.select("div[class=propertylink]");
        String path="/home/automan/Desktop/Jiuzaigou_Review.txt";
        FileWriter fw=null;
        try{
            fw=new FileWriter(path,true);
            fw.write(e1.text());
            fw.write("\n");
            fw.write(e2.text());
            fw.write("\n");
            fw.write(e3.text());
            fw.flush();
        }catch (IOException ioe){
            ioe.printStackTrace();
        }finally {
            if (fw!=null){
                try {
                    fw.close();
                }catch (IOException ioe){
                    ioe.printStackTrace();
                }
            }
        }

    }
}
